package com.qf.springbootopenapi.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data  // 生成熟悉的setter和getter方法 ， 生成toString 方法
@AllArgsConstructor  // 生成全参构造函数
@NoArgsConstructor   // 生成无参构造函数
@TableName("t_users")
public class User implements Serializable {

    @TableId(type = IdType.AUTO)
    private Integer id;

    //@JsonProperty("username")
    private String name;

    private String password;

    private String sex;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date birthday;
    
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @TableField("registTime")
    private Date registTime;
    
    @TableField("headPortrait")
    private String headPortrait;

    private String auth;
    
    public User(String name, String password, String sex, Date birthday, Date registTime, String headPortrait, String auth) {
        this.name = name;
        this.password = password;
        this.sex = sex;
        this.birthday = birthday;
        this.registTime = registTime;
        this.headPortrait = headPortrait;
        this.auth = auth;
    }
    
    public String toCSVString(){
        String s = this.getId()+","+this.getName()+","+this.getSex()+","+this.getBirthday()+","+this.getRegistTime();
        return s;
    }
    
    public static List<String> UserToCSVList(List<User> users){
        
        final ArrayList<String> returnUsers = new ArrayList<>();
        
        for (User user : users) {
            returnUsers.add(user.toCSVString());
        }
        return returnUsers;
    }
}
